import re

def parse_runebook_gump(gump_text_lines):
    """
    根据符文书Gump的固定结构解析传送点信息。
    它会定位到'20'之后的位置列表，并只处理该列表中的前16个条目。

    Args:
        gump_text_lines (list[str]): 从Gump中获取的文本行列表。

    Returns:
        list[dict]: 一个包含已解析位置的字典列表。
    """
    locations = []
    
    try:
        # 找到核心列表开始的标志 "20"
        start_index = gump_text_lines.index("20")
        # 传送点列表从 "20" 的下一行开始
        locations_start_line = start_index + 1
    except ValueError:
        # 如果没有找到 "20"，说明Gump格式不符，直接返回空列表
        return []

    # 只处理 "20" 之后的16个条目
    for i in range(16):
        line_index = locations_start_line + i
        if line_index >= len(gump_text_lines):
            break

        full_name = gump_text_lines[line_index].strip()

        # 跳过空的条目
        if full_name == "Empty":
            continue
            
        # 根据名称确定传送点类型
        location_type = "NPC"  # 默认为NPC
        if "Bank" in full_name:
            location_type = "BANK"
        elif "Trash" in full_name:
            location_type = "TRASH"
        elif "Home" in full_name:
            location_type = "HOME"

        # 根据类型确定简化后的名称
        simplified_name = ""
        if location_type == "BANK":
            simplified_name = "Bank"
        elif location_type == "TRASH":
            simplified_name = "Trash"
        elif location_type == "HOME":
            simplified_name = "Home"
        elif location_type == "NPC":
            parts = full_name.split(' ', 1)
            simplified_name = parts[1] if len(parts) > 1 else full_name
        
        # 按钮ID是根据它在16个槽位中的索引计算的 (0-15)
        # 规律由用户提供: 5, 11, 17, ...
        recall_button_id = 5 + (i * 6)
        
        locations.append({
            "name": simplified_name,
            "type": location_type,
            "index": i,
            "button_id": recall_button_id
        })

    return locations